package com.mj.app.health.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.mj.app.common_util.BaseApplication;

/**
 * ========================================
 * *
 * title: SharedPreferanceUtil
 * description:
 * *
 * Created by David Hogan on 2018/3/2.
 * ========================================
 */

public class SharedPreferanceUtil {

    private static String SP_NAME = "_sp_key";

    public static void setSp(String key, String value){

        SharedPreferences.Editor editor = getSharedPreference().edit();
        editor.putString(key,  value);
        editor.apply();
        editor.commit();
    }

    public static String getSp(String key, String defValue){
        SharedPreferences sp = getSharedPreference();
        return sp.getString(key, defValue);
    }

    private static SharedPreferences getSharedPreference(){
        return BaseApplication.getContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    }

    /**
     * 清空所有内容
     */
    public static void clear(){

        SharedPreferences.Editor editor = getSharedPreference().edit();
        editor.clear();
        editor.apply();
        editor.commit();
    }
}
